package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pojo.Sale;
import pojo.Users;
import service.SaleService;
import util.CommonResult;

import javax.servlet.http.HttpSession;
import java.math.BigDecimal;

@RestController
public class SaleController {
    @Autowired
    private SaleService saleService;

    @GetMapping("/getSaleInfo")
    public CommonResult getSaleInfo(@RequestParam("currentNo") Integer current
            , @RequestParam(value = "typeSort", required = false) Integer typeSort ){
        return saleService.getSaleInfo(current, typeSort);
    }

    @GetMapping("/addSale")
    public CommonResult addSale(Sale sale, HttpSession session) {
        sale.setTotalPrice(sale.getPrice().multiply(BigDecimal.valueOf(sale.getQuantity())));
        return saleService.addSale(sale);
    }
}
